<?php
/**
 * 分类管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-17
 * Time: 下午2:37
 */
namespace app\modules\cn\controllers;
use yii;
use app\libs\IeltsController;
use app\modules\cn\models\ResourcesPhone;

class CouponController extends IeltsController
{
    public $enableCsrfValidation = false;
    public $layout = 'cn';

    /**
     * [actionIndex 写作批改券单页]
     * @Author don
     * @Date   2021-08-12
     * @return [type]     [description]
     */
    public function actionIndex()
    {
        $uid = Yii::$app->session->get('uid');
        $remark = '雅思PC作文批改';
        $isSign = $isLogin = 0;
        if ($uid) {
            // 查询用户是否报名雅思单页
            $resource = ResourcesPhone::find()->where(['uid'=>$uid, 'remark'=>$remark])->one();
            if ($resource) {
                $isSign = 1;
            } 
            $isLogin = 1;
        } 
        $this->title = '申友雅思在线_雅思培训_雅思写作精批';
        $this->description = '申友雅思在线是上海雅思培训机构，雅思培训，雅思考试，在线免费领取价值40元的雅思写作精批活动，只为雅思提分，申友雅思在线。';
        $this->keywords = '上海雅思培训,雅思考试,雅思培训机构';
        return $this->render('index', [
            'isSign' => $isSign,
            'isLogin' => $isLogin
        ]);
    }
   
    /**
     * [actionSubmitPhone 手机号报名]
     * @Author don
     * @Date   2021-08-12
     * @return [type]     [description]
     */
    public function actionSubmitPhone()
    {
        $phone = Yii::$app->request->post('phone');
        if (!$phone) {
            die(json_encode(['code'=>0, 'message'=>'手机号不能为空！']));
        }
        $remark = '雅思PC作文批改';
        $uid = Yii::$app->session->get('uid');
        if (!$uid) {
            die(json_encode(['code'=>0, 'message'=>'请先登陆！']));
        }
        // 查询用户是否报名雅思单页
        $resource = ResourcesPhone::find()->where(['uid'=>$uid, 'remark'=>$remark])->one();
        if ($resource) {
            die(json_encode(['code'=>0, 'message'=>'已经报名了，稍后小助手会与您联系！']));
        }
        $model = new ResourcesPhone();
        $model->uid = $uid;
        $model ->phone = $phone ;
        $model ->wechat = '';
        $model ->type = 2 ;
        $model ->createTime = time() ;
        $model ->remark = $remark;
        if (!$model->save()) {
            die(json_encode(['code'=>0, 'message'=>'报名失败！']));
        }
        
        die(json_encode(['code'=>1, 'message'=>'稍后小助手会与您联系！']));
    }
}